<!Doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>大旺福--{$title}</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/assets/layui/css/admin.css" media="all">
    <link rel="stylesheet" href="/assets/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/assets/layui/css/global.css" media="all">
	<style>
		.add_goods_img{
			cursor: pointer;
		}
		.add_goods_img:hover{
			color: red;
			text-decoration: underline;
		}
		div.pic{
			height: auto;
			padding: 5px;
		}
		div.pic img{
			display: block;
			float: left;
			margin-bottom: 5px;
			margin-right: 5px;
			width: 120px;
			height: 120px;
		}
	</style>
</head>
<body>
    <div class="layui-layout layui-layout-admin">

        <!-- header start -->
        {include file="layout/header.html"}
        <!-- header end -->

        <!-- nav start-->
        {include file="layout/nav.html"}
        <!-- nav end-->

        <!-- main start -->
        <div class="layui-body site-demo">
            <div class="layui-main">
                <fieldset class="layui-elem-field layui-field-title">
                    <legend>{$title}</legend>
                </fieldset>
                <!--<div class="site-block">
				</div>-->
                	<form class="layui-form" action="/product/productUpdate/?successUrl={$successUrl}" method="post">
					<input type="hidden" name="id" value="{$productBaseData.id}" />
					<input type='hidden' name="img" value="{$productBaseData.product_image}"/>
					<input type='hidden' name="_imgList" value="" lay-verify="imgList" />                		
					<div class="layui-tab">
					  <ul class="layui-tab-title">
					    <li class="layui-this">商品信息</li>
					    <li>商品描述</li>
					    <li>营销选项</li>
					  </ul>
					  <div class="layui-tab-content">
					    <div class="layui-tab-item layui-show">
							<div class="layui-form-item">
								<label class="layui-form-label">商品名称</label>
								<div class="layui-input-block">
									<input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入商品名称" class="layui-input" value="{$productBaseData.product_name}">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">所属供应商</label>
								<div class="layui-input-block">
									<select name="shop" lay-verify="shop" lay-filter="shop">
										<option value="">请选择所属供应商</option>
										{foreach from=$shop item=one}
										<option value="{$one.id}" {if $one.id == $productBaseData.shop_id}selected{/if}>{$one.shop_name}</option>
										{/foreach}
									</select>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">所属分类</label>
								<div class="layui-input-block">
									<input type="hidden" name="categroy_id" value="{$categoryids}" lay-verify="categroy">
									<button type="button" class="layui-btn add-category" style="margin-top:5px;"><i class="layui-icon">&#xe608;</i> <span>选择分类</span></button><span style="color: red;">  *请选择二级分类</span>
									<div class="category-list layui-clear site-block layui-hide" style="padding:10px;">
										<ul id="category-tree" class="layui-box layui-tree" style="margin-bottom:10px;"></ul>
									</div>
									<div class="category-selected-list layui-clear site-block" style="padding:10px;">
										{foreach from=$productCategory item=category}
											<button class="layui-btn layui-btn-mini layui-btn-warm" type="button">{$category.category_name}</button>
										{/foreach}
									</div>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">商品品牌</label>
								<div class="layui-input-block">
									<select name="brand" lay-filter="brand">
										<option value="">请选择品牌</option>
										{foreach from=$brand item=one}
										<option value="{$one.id}" {if $one.id == $productBaseData.brand_id}selected{/if}>{$one.brand_name}</option>
										{/foreach}
									</select>
									{literal}
									<script id="brandTemplate" type='text/html'>
										<option value="">请选择品牌</option>
										{{#  layui.each(d , function(index, item){ }}
										<option value="{{item.id}}">{{item.brand_name}}</option>
										{{# }) }}
									</script>
									{/literal}
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">附属属性</label>
								<div class="layui-input-block">
									<table class="layui-table">
										<thead>
										<tr>
											<th>排序</th><th>计量单位显示</th>
										</tr>
										</thead>
										<tbody>
										<tr>
											<td><input class="layui-input" name="sort" type="text" value="{if $productBaseData.f_order}{$productBaseData.f_order}{else}99{/if}"></td>
											<td><input class="layui-input" name="unit" type="text" value="{if $productBaseData.precise_unit}{$productBaseData.precise_unit}{else}箱{/if}"></td>
										</tr>
										</tbody>
									</table>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">基本属性</label>
								<div class="layui-input-block">
									<button class="layui-btn layui-btn-small add-base-attribute" type="button"><i class="layui-icon">&#xe61f;</i>添加基本属性</button>
									<div class="layui-clear site-block" style="padding:10px;" id="base-attribute-list">

									</div>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">搜索属性</label>
								<div class="layui-input-block">
									<button class="layui-btn layui-btn-small add-search-attribute" type="button"><i class="layui-icon">&#xe61f;</i>添加搜索属性</button>
									<div class="layui-clear site-block" style="padding:10px;" id="search-attribute-list">

									</div>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">规格属性</label>
								<div class="layui-input-block">
									<button class="layui-btn layui-btn-small add-sku-attribute" type="button"><i class="layui-icon">&#xe61f;</i>添加规格属性</button>
									<div class="layui-clear site-block" style="padding:10px;"id="sku-attribute-list">

									</div>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">基本数据</label>
								<div class="layui-input-block">
									<div class="con">
										<table class="layui-table">
											<thead id="goodsBaseHead"></thead>

											<!--商品标题模板-->
											{literal}
											<script id="goodsHeadTemplate" type='text/html'>
												<tr>
													<th>商品货号</th>
													{{# var isProduct = false; }}
													{{#  layui.each(d , function(index, item){ }}
													{{# isProduct = true; }}
													<th>{{ item.name }}</th>
													{{# }) }}
													<th>库存</th>
													<th>市场价</th>
													<th>销售价</th>
													<th>成本价</th>
													<th>返现</th>
													<th>会员分成</th>
													<th>商家分成</th>
													<th>区域经理分成</th>
													<th>图片</th>
													{{# if(isProduct == true){ }}
													<th>操作</th>
													{{# } }}
												</tr>
											</script>
											{/literal}

											<tbody id="goodsBaseBody"></tbody>

											<!--商品内容模板-->
											{literal}
											<script id="goodsRowTemplate" type="text/html">
												{{# var i=0;}}
												{{# layui.each(d, function(index, item){ }}
												<tr class='td_c'>
													<td><input class="small" name="_goods_no[{{ i }}]" type="text" value="{{ item['goods_no'] ? item['goods_no'] : item['products_no'] }}" /></td>
													{{# var isProduct = false;}}
													{{# var specArrayList = layui.tools.parseJSON(item['spec_array']); }}
													{{# layui.each(specArrayList, function(index, item){ }}
													{{# var itemValue = layui.tools.parseJSON(item['value']); }}
													<input type='hidden' data-id="{{ item.id }},{{itemValue.id}}" name="_spec_array[{{ i }}][]" value='{"id":"{{ item.id }}","type":"{{ item.type }}","value":"{{ itemValue.id }}","name":"{{ item.name }}"}' />
													{{# isProduct = true;}}
													<td>
														{{ itemValue.value_name }}
													</td>
													{{# }) }}
													<td><input class="tiny" name="_store_nums[{{ i }}]" type="text"  value="{{ item['store_nums'] ? item['store_nums'] : 100 }}" /></td>
													<td><input class="tiny" name="_market_price[{{ i }}]" type="text"  value="{{ item['market_price'] ? item['market_price'] : 0.00 }}" /></td>
													<td>
														<input class="tiny" name="_sell_price[{{ i }}]" type="text"  value="{{ item['sell_price'] ? item['sell_price'] : 0.00 }}" />
													</td>
													<td><input class="tiny" name="_cost_price[{{ i }}]" type="text"   value="{{ item['cost_price'] ? item['cost_price'] : 0.00 }}" /></td>
													<td><input class="tiny" name="_cash_back[{{ i }}]" type="text"   value="{{ item['cash_back'] ? item['cash_back'] : 0.00 }}" /></td>
													<td><input class="tiny" name="_member_proportion[{{ i }}]" type="text"   value="{{ item['member_proportion'] ? item['member_proportion'] : 0.00 }}" /></td>
													<td><input class="tiny" name="_proportion[{{ i }}]" type="text"   value="{{ item['proportion'] ? item['proportion'] : 0.00 }}" /></td>
													<td><input class="tiny" name="_area_proportion[{{ i }}]" type="text"   value="{{ item['area_proportion'] ? item['area_proportion'] : 0.00 }}" /></td>
													<td>
														{{# if(item['goods_img']){ }}
														<img src="http://img.dawangfu.com/{{item['goods_img']}}" width="50" height="50" class="add_goods_img">
														{{# }else{ }}
														<span class="add_goods_img">添加</span>
														{{# } }}
														<input type="hidden" name="_goods_img[{{ i }}]" value="{{ item['goods_img'] ? item['goods_img'] : '' }}">
													</td>
													{{# if(isProduct == true){ }}
													<td>
														<input type="radio" name="is_default" value="{{index}}" title="默认"{{# if(item.is_default == 1){ }} checked {{# } }}>
														<button class="layui-btn layui-btn-mini layui-btn-danger"  onclick="delProduct(this);" type="button"><i class="layui-icon">&#x1006;</i></button>
													</td>
													{{# } }}
												</tr>
												{{# i++; }}
												{{# }) }}
											</script>
											{/literal}
										</table>
									</div>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">是否上架</label>
								<div class="layui-input-block">
									<input type="radio" name="shelves" value="0" title="否" {if $productBaseData.shelf eq 0}checked {/if}>
									<input type="radio" name="shelves" value="1" title="是" {if $productBaseData.shelf eq 1}checked {/if}>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">是否备货</label>
								<div class="layui-input-block">
									<input type="radio" name="stock" value="0" title="否" {if $productBaseData.stock eq 0}checked {/if}>
									<input type="radio" name="stock" value="1" title="是" {if $productBaseData.stock eq 1}checked {/if}>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">商品图片</label>
								<div class="layui-input-block">
									<input type="file" name="file" lay-type="images" class="layui-upload-file">
								</div>
								<div class="layui-input-block" id="thumbnails" style="min-height:150px;">

								</div>
								<!--图片模板-->
								{literal}
								<script type="text/html" id="picTemplate">
									<span class='pic'>
										<img name="picThumb" {{# if(d.current == 1){ }} class="current" {{# } }} onclick="defaultImage(this);" style="margin:5px; opacity:1;width:100px;height:100px" src="{{ d.img_url }}" alt="{{ d.img_path }}" />
										<p>
											<a class='orange layui-icon' href='javascript:void(0)' onclick="moveBefore(this)">&#xe603;<!--<img src="/assets/images/arrow_left.png" title="左移动" alt="左移动" />--></a>
											<a class='orange layui-icon' href='javascript:void(0)' onclick="delImage(this)">&#x1007;<!--<img src="/assets/images/sign_cacel.png" title="删除" alt="删除" />--></a>
											<a class='orange layui-icon' href='javascript:void(0)' onclick="moveAfter(this)">&#xe602;<!--<img src="/assets/images/arrow_right.png" title="右移动" alt="右移动" />--></a>
										</p>
									</span>
								</script>
								{/literal}
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label"></label>
								<div class="layui-input-block">
									<button class="layui-btn layui-btn-big" lay-submit  lay-filter="save">保存</button>
								</div>
							</div>
					    </div>
					    <div class="layui-tab-item">
						  <div class="layui-form-item layui-form-text">
						    <div class="layui-input-block">
						      <textarea class="layui-textarea layui-hide" name="content" lay-verify="content" id="productContent">
						      	{$productBaseData.product_info}
						      </textarea>
						    </div>
						  </div>						    	
					    </div>
					    <div class="layui-tab-item">
						<table class="layui-table no-border <!--form_table-->">
							<tbody>
								<tr>
									<th width="10%">SEO关键词：</th>
									<td><input name="keywords" type="text" value="{$productBaseData.seo_keywords}" class="layui-input"></td>
								</tr>
								<tr>
									<th>SEO描述：</th>
									<td>
									  <div class="layui-form-item layui-form-text">
									    <div class="layui-input-inline">
									      <textarea placeholder="请输入内容" class="layui-textarea" name="description">
									      	{$productBaseData.seo_description}
									      </textarea>
									    </div>
									  </div>										
									</td>
								</tr>
							</tbody>
						</table>					
					    </div>
					  </div>
					</div>
					</form>

            </div>
        </div>
        <!-- main end -->

    </div>
    {literal}
    <script type="text/html" id="add_attribute_tpl">
		<div class="pop_win">
			<table class="spec" width="95%" cellspacing="0" cellpadding="0" border="0">
				<tbody>
					<tr>
						<td>
							<h3>请选择{{ d.title }}</h3>
							<div class="cont" style="height:285px;">								
								<ul id="specs">
									
									{{#  layui.each(d.list, function(index, item){ }}
										{{# if(index != 'ids'){}}
										<li>
											<label>
												<input type="checkbox" autocomplete="off" name="spec" onclick="selSpect(this,{{ item.id }})" value='{"id":"{{ item.id }}","name":"{{ item.attribute_name }}","type":"{{ item.attribute_type }}","form_type":"{{ item.form_type }}","value":"{{#  if(item.values){ }}{{ layui.tools.encodeJSON(item.values) }}{{# } }}"}' />{{ item.attribute_name }}
											</label>
										</li>
										{{# } }}
									{{#  }); }}
									 
									{{#  if(d.list.length === 0){ }}
									  无数据
									{{#  } }}									
								</ul>
			
							</div>
							<p>没有找到需要的属性？</p>
							<p><button type="button" class="btn" onclick="addNewSpec()"><span class="add">添加新属性</span></button></p>
						</td>
						<td>
							<h3>属性可选值预览区</h3>
							<div class="cont" style="height:285px;">
								<p>请在左侧列表选择属性！</p>
								<ul class="goods_spec_box">
								</ul>
							</div>					
						</td>
					</tr>
				</tbody>
			</table>
		</div>
	</script>
	
	<script type="text/html" id="add_attribute_selected_tpl">
		{{#  layui.each(d.list, function(index, item){ }}
			<li>
				<span>{{ item.value_name }}</span>
			</li>
		{{#  }); }}
		 
		{{#  if(d.list.length === 0){ }}
		  无数据
		{{#  } }} 
	</script>
	<script type="text/html" id="create_attribute_checked_tpl">
		{{#  layui.each(d.list, function(index, item){ }}
		<div class="layui-form-item">
			<label class="layui-form-label">{{ item.name }}：</label>
				{{# if(item.form_type == 'select'){ }}
				<div class="layui-input-inline">
					<select name="attr_{{d.type}}_{{ index }}" lay-filter="{{d.type}}">
						<option value="">请选择{{ item.name }}</option>
						{{#  layui.each(item.values, function(i,e){ }}
							<option data-value='{"id":"{{ item.id }}","name":"{{ item.name }}","type":"{{ item.type }}","form_type":"{{ item.form_type }}","value":"{{ layui.tools.encodeJSON(e) }}"}'  value='{{item.id}},{{e.id}}' {{# if (e.checekd == 1){ }} selected {{# } }}>{{e.value_name}}</option>
						{{#  }); }}
					</select>
				</div>
				{{# } else if(item.form_type == 'checkbox'){ }}
				    <div class="layui-input-block">
						{{#  layui.each(item.values, function(i,e){ }}
							<input type="checkbox" data-id="{{ item.id }},{{e.id}}" name="attr_{{d.type}}_{{ index }}[]" title="{{e.value_name}}" lay-filter="{{d.type}}" data-value='{"id":"{{ item.id }}","name":"{{ item.name }}","type":"{{ item.type }}","form_type":"{{ item.form_type }}","value":"{{ layui.tools.encodeJSON(e) }}"}' value='{{item.id}},{{e.id}}' {{# if (e.checekd == 1){ }} checked {{# } }}>
						{{#  }); }}				    	
				    </div>
				{{# } else if(item.form_type == 'radio'){ }}
					<div class="layui-input-block">
				      	{{#  layui.each(item.values, function(i, e){ }}
							<input type="radio" name="attr_{{d.type}}_{{ index }}" 
								title="{{e.value_name}}" 
								lay-filter="{{d.type}}" 
								data-value='{"id":"{{ item.id }}","name":"{{ item.name }}","type":"{{ item.type }}","form_type":"{{ item.form_type }}","value":"{{ layui.tools.encodeJSON(e) }}"}'  
								value='{{item.id}},{{e.id}}' {{# if (e.checekd == 1){ }} checked {{# } }}'>
						{{#  }); }}	
				    </div>
				{{# } else if(item.form_type == 'text'){ }}
					<div class="layui-input-inline">
				    		<input type="text" name="attr_{{d.type}}_{{ index }}" data-id="{{ item.id }}" required lay-filter="{{d.type}}" placeholder="请输入{{item.name }}" autocomplete="off" class="layui-input">
				    </div>
				{{# }}}
			
		</div>
		{{#  }); }}
	</script>	
	{/literal}
    {include file="layout/footerJs.html"}
    <script src="/assets/layui/js/product/product_add.js"></script>
</body>
</html>